#include "gofgame/common/graphics/SolidBrush.h"

using namespace gofgame::common::graphics;

SolidBrush::SolidBrush(const ccColor4F &color) {
	this->color = color;
}

SolidBrush::SolidBrush(float r, float g, float b, float a) {
	this->color.r = r;
	this->color.g = g;
	this->color.b = b;
	this->color.a = a;
}

bool SolidBrush::isTransparent() const {
	return this->color.a == 0;
}

const ccColor4F &SolidBrush::getColor() const {
	return this->color;
}

void SolidBrush::onFillRect(float left, float top, float width, float height) {
	GLfloat vertexArr[] = {
		left, top,
		left + width, top,
		left, top + height,
		left + width, top + height,
	};
	ccColor4F clr = this->getColor();
	GLfloat colorArr[] = {
		clr.r, clr.g, clr.b, clr.a,
		clr.r, clr.g, clr.b, clr.a,
		clr.r, clr.g, clr.b, clr.a,
		clr.r, clr.g, clr.b, clr.a,
	};
	CCGLProgram *program = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor);
	program->use();
	program->setUniformsForBuiltins();
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color);
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertexArr);
	glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colorArr);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}